import { _decorator, Component, instantiate, tween, Vec3, Label, Prefab} from 'cc';
import { Card } from './Card';
import { CpgStack } from './CpgStack';
const { ccclass, property } = _decorator;

@ccclass('CardManager') // 用 @ccclass 声明类为 Cocos 组件
export class CardManager extends Component {
    // 通过 @property 让编辑器可以配置属性
    @property(Prefab) card!: Prefab;
    @property(Prefab) cardstack!: Prefab;

	static instance: CardManager;
    static kingCardIDs:[];

    onLoad() {
        CardManager.instance = this;

    }

    static setKingCard(cardIDs:[] = []) {
        this.kingCardIDs = cardIDs;
    }
    
    static isKingCard(cardID:number) {
        const kingCardIDs = this.kingCardIDs;
        for(let i = 0; i < kingCardIDs.length; i++)
        {
            if(kingCardIDs[i] == cardID)
            {
                return true;
            }
        }
        return false;
    }

    static createDeskCard(open:boolean = false) {
        const cardNode = instantiate(CardManager.instance.card);
        let card : Card | null = cardNode.getComponent(Card);
        card?.setBaseCard(open);
        return cardNode;
    }

    static createHandCard(self:boolean = false) {
        const cardNode = instantiate(CardManager.instance.card);
        let card : Card | null = cardNode.getComponent(Card);
        card?.setHandCard(self);
        return cardNode;
    }

    static createStackCard(cardIDs:number[]) {
        const cardNode = instantiate(CardManager.instance.cardstack);
        let stack : CpgStack | null = cardNode.getComponent(CpgStack);
        stack?.setData(cardIDs);
        return cardNode;
    }

}
